export default {
    /**
     * 转换成正常时间
     * @param {*} format
     */
    format(format) {
        var date = new Date(format);
        var y = 1900 + date.getYear();
        var m = "0" + (date.getMonth() + 1);
        var d = "0" + date.getDate();
        return y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length);
    },

    /**
     * 验证身份证长度和类型
     * @param {*} card
     */
    isCardNo(card) {
        //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
        let reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
        if (!reg.test(card)) {
            return false;
        }
        return true;
    },

    /**
     * 验证有效手机
     * @param {*} phone
     */
    isPhone(phone) {
        let reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
        if (!reg.test(phone)) {
            return false;
        }
        return true;
    },

    /**
     * 判断是否金额
     * @param {*} money
     */
    isMoney(money) {
        let reg = /^\d+\.?\d{0,2}$/
        if (!reg.test(money)) {
            return false;
        }
        return true;
    },

    /**
     * 判断是否数字
     * @param {*} number
     */
    isNumber(number) {
        let reg = /^[0-9]+.?[0-9]*/;
        if (!reg.test(number)) {
            return false;
        }
        return true;
    },

    /**
     * 获取URL参数
     * @param {*} paraName
     */
    GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                arr = arrPara[i].split("=");

                if (arr != null && arr[0] == paraName) {
                    return arr[1];
                }
            }
            return "";
        }
        else {
            return "";
        }
    },

    /**
     * YYYY-MM-DD 转 yyyymmdd
     * @param {*} DateStr
     */
    ConverToDate(DateStr) {
        if (/^\d{4}-\d{2}-\d{2}$/.test(DateStr)) {
            let date = DateStr;
            DateStr = date.replace(/\-/g, "");
        }
        return DateStr;
    },

    /**
     * yyyymmdd 转 YYYY-MM-DD
     * @param {*} DateStr
     */
    DateToConver(DateStr) {
        if (/^(\d{4})(\d{2})(\d{2})$/.test(DateStr)) {
            let date = DateStr.toString();
            DateStr = date.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3");
        }
        return DateStr;
    },

    parseTime(d) {
        let date = new Date(d);
        let newDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
        return newDate;
    }
}
